package com.itboye.ihomebank.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.RepairPersenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

import java.util.Observable;
import java.util.Observer;

/**
 * 修改维修金额
 * 
 */
public class ActivityXiuGaiMoney extends BaseOtherActivity implements Observer {
	View v_statusbar;
	private ImageView close_icon;// 返回图片
	private TextView add_shap_title_tv;// 标题
	EditText jine_et, mobile_et;
	TextView jine_ok;// 完成

	Intent intent;
	String id;
	private String uid;// id
	TextView yzm_et;
	RepairPersenter repairPersenter;
	private String jin;
	private String mobile;
	UserPresenter userPresenter;
	private String code;
	private String yzm;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.jine_ok:
			showProgressDialog("请稍后", false);
			repairPersenter = new RepairPersenter(this);
//			yzm = yzm_et.getText().toString();
//			if (yzm.equals("")) {
//				ByAlert.alert("请输入验证码");
//				return;
//			}
			jin = jine_et.getText().toString();
			if (jin.equals("")) {
				ByAlert.alert("请输入金额");
				return;
			}
//			if (!code.equals(yzm)) {
//				ByAlert.alert("验证码错误");
//				return;
//			}
			repairPersenter.xiuGaiMoney(id, uid, jin, yzm);
			break;
		case R.id.yzm_et:

			break;
		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_xiugai_money;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		setStatusBarHeight(v_statusbar);
		add_shap_title_tv.setText("修改维修金额");
		userPresenter = new UserPresenter(this);
		intent = this.getIntent();

		if (intent != null) {
			id = intent.getStringExtra("id");
		}
		mobile = intent.getStringExtra("mobile");
		uid = (String) SPUtils.get(this, null, SPContants.USER_ID, "");
//		userPresenter.send(mobile, "8");
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		// ByAlert.alert(entity.getData());
		if (entity != null) {
			if (!entity.getCode().equals(0)) {

				if (entity.getEventType() == RepairPersenter.xiugaiMoney_success) {
					ByAlert.alert(entity.getData());
					finish();

				} else if (entity.getEventType() == RepairPersenter.xiugaiMoney_fail) {
					ByAlert.alert(entity.getData());
				} 
//				else if (entity.getEventType() == UserPresenter.send_success) {
//					code = entity.getData().toString();
//
//					ByAlert.alert(entity.getData());
//				} else if (entity.getEventType() == UserPresenter.send_fail) {
//					ByAlert.alert(entity.getData());
//				}
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
		}

	}

}
